#! /usr/bin/python

import math

def sumOfProperDivisors(n):
    if n == 1: return 0
    r = int(math.sqrt(n))
    if r*r == n: 
	s = 1+r
	r = r - 1
    else: s = 1
    if n%2 != 0:
	f = 3
	step = 2
    else:
	f = 2
	step = 1
    while(f <= r):
	if n%f == 0:
	   s += f + n/f
	f += step	   
    return s

ll = [83328, 47616, 274924, 31704, 295488, 97946, 22744, 152990, 376736, 122410, 19116, 243760, 17716, 177792, 358336, 19916, 629072, 285778, 22976, 418904, 589786, 366556, 48976, 381028, 14316, 294896, 275444, 45946]
ll.sort()
print ll

ml = 0
chain = set()
visited = set()
for i in range(10000, 1000000):    
    if i in visited: continue
    current = sumOfProperDivisors(i)
    if current > 1000000 or i >= current: continue
    ll = set([i, current])
    while (1):	
	next = sumOfProperDivisors(current)
	if next > 1000000: break
	if next == i: 
           if len(ll) > ml: 
	      ml = len(ll)
	      chain = ll   
	   break
	if next == 0 or next in ll: break
	if next not in ll: 
	   current = next
           ll.add(next)
    #print visited

print chain, len(chain)
